<?php
// 本类由系统自动生成，仅供测试用途
class CommAction extends Action{
    public function _initialize(){
		
		$this->assign('sys_name',c('CMS_NAME'));

    	if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			//重定向
			
			redirect(PHP_FILE .C('USER_AUTH_GATEWAY'));
		}

        
     }
	/**
	 +------------------------------------------------------------------------------
	 * 公共 文件上传方法
	 +------------------------------------------------------------------------------
	 * $path    string  上传路径
	 * $maxsize int     上传文件最大值
	 * $thumb   boolean 是否生成缩略图
	 * $width   int     缩略图最大宽度
	 * $height  int     缩略图最大高度
	 * $autosub boolean 是否使用子目录保存文件
	 +------------------------------------------------------------------------------
 	*/

	function _upload($path,$thumb = false,$width,$height,$autosub = false,$maxsize){
		import("ORG.Net.UploadFile");
        $upload = new UploadFile(); 
		
		
		
        isset($maxsize) ? $upload->maxSize = $maxsize : $upload->maxSize = 1048576*2; //2M
		isset($path) ? $upload->savePath = $savepath = "./Attachments/".$path."/" : $upload->savePath = "./Attachments/Others/";

		if(!is_dir($savepath)) @mk_dir($savepath);
        $upload->allowExts = explode(',','gif,png,jpg,jpeg,pdf,rar,doc,txt'); 

		if($thumb){
			$upload->thumb = true; 
			$upload->thumbPrefix = '';
			$upload->thumbSuffix = '_thumb';
			isset($wideh) ? $upload->thumbMaxWidth = $width : $upload->thumbMaxWidth = "300"; 
			isset($height) ? $upload->thumbMaxHeight = $height : $upload->thumbMaxHeight = "400"; 
		}
    	if($autosub){
			$upload->autoSub = true;
			$upload->subType = 'date';
        	$upload->saveRule = 'com_create_guid'; 
			$upload->dateFormat = 'Y/m/d'; 	
		}
        if(!$upload->upload()){  
           	$this->error($upload->getErrorMsg()); 
        }else{ 
			$imginfo = $upload->getUploadFileInfo();
			
			foreach($imginfo as $k=>$data_arr){
				
				$save_arr[$data_arr['up_flag']] = $data_arr['savename'];				
			}
			$imginfo = $save_arr;
        }
		
		return $imginfo;		

	}

}
?>